package com.kedacom.ctsp.authz.oauth2;

import com.kedacom.ctsp.authz.oauth2.core.OAuth2Exception;
import com.kedacom.ctsp.lang.http.HttpStatusEnum;
import com.kedacom.ctsp.web.controller.message.ResponseMessage;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author zhouhao
 */
@RestControllerAdvice
public class OAuth2ServerErrorControllerAdvice {

    @ExceptionHandler(OAuth2Exception.class)
    @ResponseStatus(HttpStatus.OK)
    public ResponseMessage<String> error(OAuth2Exception e) {
        return ResponseMessage.error(HttpStatusEnum.FORBIDDEN.value(),String.valueOf(e.getErrorType().code()), e.getErrorType().message());
    }
}
